package com.inspur.dgov.bsp.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.inspur.dgov.bsp.system.entity.PubConfig;
import com.inspur.dgov.bsp.system.entity.PubDict;
import com.inspur.dgov.bsp.system.mapper.PubConfigMapper;
import com.inspur.dgov.bsp.system.service.PubConfigService;
import com.inspur.dgov.bsp.system.service.PubDictService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 字典类别信息 服务实现类
 *
 * @author chiyupei
 * @version 1.0
 * @since 1.0
 */
@Slf4j
@Service
@AllArgsConstructor
public class PubConfigServiceImpl extends ServiceImpl<PubConfigMapper, PubConfig> implements PubConfigService {

    @Autowired
    private PubDictService pubDictService;

    /**
     * 更新字典类别
     * @param config
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean updateConfig(PubConfig config) {
        boolean rs = super.updateById(config);
        //更新字典项
        PubDict dict = new PubDict();
        dict.setConfigCode(config.getCode());
        UpdateWrapper<PubDict> updateWrapper = new UpdateWrapper<>();
        updateWrapper.lambda().eq(PubDict::getConfigId, config.getId());
        this.pubDictService.update(dict, updateWrapper);
        return rs;
    }
}
